package com.lfy.kcat.user.config;

import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
import cn.dev33.satoken.stp.StpLogic;
import cn.dev33.satoken.strategy.SaStrategy;
import cn.dev33.satoken.util.SaFoxUtil;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author leifengyang
 * @version 1.0
 * @date 2025/9/13 14:50
 * @description:
 */
@Slf4j
@Configuration
public class SaTokenConfigure {


    /**
     * 给容器中配置 jwt 规则
     */
    @Bean
    StpLogic  stpLogic(){
        return new StpLogicJwtForSimple();
    }


    /**
     * 重写 Sa-Token 框架内部算法策略
     */
/*    @PostConstruct //对象构造器执行后，也就是这类的对象刚创建出来
    public void rewriteSaStrategy() {
        // 重写 Token 生成策略
        SaStrategy.instance.createToken = (loginId, loginType) -> {
            log.info("loginId={}, loginType={}", loginId, loginType);
            return "aaabbb_"+ SaFoxUtil.getRandomString(16)+"_"+loginId;    // 随机60位长度字符串
        };
    }*/

}
